import { ExclamationCircleOutlined } from '@ant-design/icons-vue'
import { createVNode, ref, reactive } from 'vue'
import { Modal, message } from 'ant-design-vue'
export function hint() {
  //对话框，确认、取消
  // 示例： Confirm('是否删除?') 第二个参数是VNode可省略
  const Confirm = (title, VNode = '') => {
    return new Promise((resolve, reject) => {
      Modal.confirm({
        title,
        icon: createVNode(ExclamationCircleOutlined),
        content: createVNode(
          'div',
          {
            style: 'color:red;'
          },
          VNode
        ),
        onOk() {
          resolve(true) // 解决 Promise 并传递 true
        },
        onCancel() {
          reject(false) // 拒绝 Promise 并传递 false
        },
        class: 'test'
      })
    })
  }
  // 提示框
  // 示例：  msg('success', '删除成功')
  const msg = (state, text) => {
    message[state](text)
  }
  return { Confirm, msg }
}
// 分页
export function Paging() {
  const current = ref(1)
  const pageSize = ref(10)
  const home = reactive({
    page: 1,
    pageSize: 10
  })
  const onChange = async (fn, id) => {
    fn(id, { page: current.value, pageSize: pageSize.value })
  }
  const changePage = (newPage, page) => {
    home.page = newPage
    home.pageSize = page
    // console.log(home)

    // current.value = newPage // 将新页码赋值
  }
  return { current, pageSize, home, onChange, changePage }
}
